package com.mobimap.nhom9.gui.utls;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.SparseArray;

import com.mobimap.nhom9.gui.R;

public class GuiHelper {

	//GET DEFINE ICON
	private static SparseArray<Integer> _placeIconResource;
	public static Integer getDichVuIconResource(int key) {
		if (_placeIconResource == null){
			_placeIconResource = new SparseArray<Integer>();
			_placeIconResource.put(0, R.drawable.ptype_0_house);
			_placeIconResource.put(1, R.drawable.ptype_1_postoffice);
			_placeIconResource.put(42, R.drawable.ptype_42_museum);
			_placeIconResource.put(51, R.drawable.ptype_51_hospital);
			_placeIconResource.put(104, R.drawable.ptype_104_market);
			_placeIconResource.put(112, R.drawable.ptype_112_pagoda);
			_placeIconResource.put(136, R.drawable.ptype_136_park);
			_placeIconResource.put(383, R.drawable.ptype_383_hotel);
			_placeIconResource.put(483, R.drawable.ptype_483_bank);
			_placeIconResource.put(509, R.drawable.ptype_509_temple);
			_placeIconResource.put(623, R.drawable.ptype_623_stadium);
			_placeIconResource.put(750, R.drawable.ptype_750_consulate);
			_placeIconResource.put(781, R.drawable.ptype_781_school);
			_placeIconResource.put(792, R.drawable.ptype_792_uyban);
			_placeIconResource.put(889, R.drawable.ptype_889_atm);
			_placeIconResource.put(890, R.drawable.ptype_890_coffee);
			_placeIconResource.put(891, R.drawable.ptype_891_petrol);
			_placeIconResource.put(894, R.drawable.ptype_894_supermarket);
			_placeIconResource.put(895, R.drawable.ptype_895_wc);
			_placeIconResource.put(897, R.drawable.ptype_897_university);
			_placeIconResource.put(898, R.drawable.ptype_898_building);
			_placeIconResource.put(899, R.drawable.ptype_899_theater);
			_placeIconResource.put(901, R.drawable.ptype_901_library);
			
		}
		return _placeIconResource.get(key);
	}

	public static Bitmap decodeSampledBitmapFromResource(String path, int reqWidth,
			int reqHeight) {

		// First decode with inJustDecodeBounds=true to check dimensions
		final BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(path, options);

		// Calculate inSampleSize
		options.inSampleSize = calculateInSampleSize(options, reqWidth,
				reqHeight);

		// Decode bitmap with inSampleSize set
		options.inJustDecodeBounds = false;
		return BitmapFactory.decodeFile(path, options);
	}

	public static int calculateInSampleSize(BitmapFactory.Options options,
			int reqWidth, int reqHeight) {
		// Raw height and width of image
		final int height = options.outHeight;
		final int width = options.outWidth;
		int inSampleSize = 1;

		if (height > reqHeight || width > reqWidth) {
			if (width > height) {
				inSampleSize = Math.round((float) height / (float) reqHeight);
			} else {
				inSampleSize = Math.round((float) width / (float) reqWidth);
			}
		}
		return inSampleSize;
	}
}